<?xml version="1.0" encoding="UTF-8"?>
<!-- 
/**
 * Copyright 2011 MaGdev
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *    * The names of the authors may not be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @package      Mashape API-Documentor
 * @author       Marco Graetsch <info@magdev.de>
 * @copyright    2011 Marco Graetsch.development
 * @license      http://opensource.org/licenses/bsd-license.php New BSD License
 * @link         https://code.google.com/p/apidocumentor/
 */
 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="default/global.xsl"/>
    
    <xsl:template name="home">
        <h2>
            <xsl:value-of select="$title" />
            <xsl:text> Documentation</xsl:text>
        </h2>
        <xsl:if test="$description!=''">
            <p><xsl:value-of select="$description"/></p>
        </xsl:if>
        <ul data-role="listview" data-inset="true">
            <li data-role="list-divider" role="heading" class="subheading">
                <xsl:text>API Reference</xsl:text>
            </li>
            <li>
                <a href="#objects">
                    <xsl:text>Objects</xsl:text>
                </a>
            </li>
            <li>
                <a href="#methods">
                    <xsl:text>Methods</xsl:text>
                </a>
            </li>
        </ul>
        <xsl:if test="$apiUrl!='' or $authorUrl!=''">
	        <ul data-role="listview" data-inset="true">
	            <li data-role="list-divider" role="heading" class="subheading">
	                <xsl:text>Mashape-Profiles</xsl:text>
	            </li>
	            <xsl:if test="$apiUrl!=''">
		            <li>
		                <xsl:element name="a">
		                    <xsl:attribute name="href">
		                        <xsl:value-of select="$apiUrl" />
		                    </xsl:attribute>
		                    <xsl:attribute name="rel">external</xsl:attribute>
		                    <xsl:value-of select="$title" />
		                </xsl:element>
		            </li>
		        </xsl:if>
		        <xsl:if test="$authorUrl!=''">
		            <li>
		                <xsl:element name="a">
		                    <xsl:attribute name="href">
		                        <xsl:value-of select="$authorUrl" />
		                    </xsl:attribute>
		                    <xsl:attribute name="rel">external</xsl:attribute>
		                    <xsl:value-of select="$authorName" />
		                </xsl:element>
		            </li>
		        </xsl:if>
	        </ul>
	    </xsl:if>
    </xsl:template>

    <xsl:template name="objects">
        <ul data-role="listview" data-inset="true" data-filter="true">
            <li data-role="list-divider" role="heading">
                <xsl:text>Objects</xsl:text>
            </li>
            <xsl:for-each select="//object">
                <li>
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:text>#</xsl:text>
                            <xsl:value-of select="concat('object', @name)" />
                        </xsl:attribute>
                        <xsl:value-of select="@name" />
                    </xsl:element>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>


    <xsl:template name="methods">
        <ul data-role="listview" data-inset="true" data-filter="true">
            <li data-role="list-divider" role="heading">
                <xsl:text>Methods</xsl:text>
            </li>
            <xsl:for-each select="//method">
                <li>
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:text>#</xsl:text>
                            <xsl:value-of select="concat('method', @name)" />
                        </xsl:attribute>
                        <xsl:value-of select="@name" />
                    </xsl:element>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>


    <xsl:template match="object">
        <xsl:element name="article">
            <xsl:attribute name="data-role">page</xsl:attribute>
            <xsl:attribute name="data-theme">d</xsl:attribute>
            <xsl:attribute name="id">
                <xsl:value-of select="concat('object', @name)" />
            </xsl:attribute>
            <header data-role="header" data-position="fixed">
                <h1>
                    <xsl:value-of select="$title" />
                    <xsl:text> API | </xsl:text>
                    <xsl:value-of select="@name" />
                </h1>
                <xsl:call-template name="menu" />
            </header>
            <section data-role="content" data-theme="b">
                <div class="object">
                    <ul data-role="listview" data-inset="true">
                        <li data-role="list-divider" role="heading">
                            <xsl:value-of select="@name" />
                        </li>
                        <li data-role="list-divider" class="subheading">
                            <xsl:text>Class</xsl:text>
                        </li>
                        <li>
                            <xsl:value-of select="@class" />
                        </li>
                        <li data-role="list-divider" class="subheading">
                            <xsl:text>Properties</xsl:text>
                        </li>
                        <xsl:apply-templates select="field" />
                        <li data-role="list-divider" class="subheading">
                            <xsl:text>Returned by</xsl:text>
                        </li>
                        <xsl:for-each select="//method/result[@object=current()/@name]/..">
                            <li>
                                <xsl:element name="a">
                                    <xsl:attribute name="href">
                                    <xsl:value-of
                                        select="concat('#method', @name)" /></xsl:attribute>
                                    <xsl:value-of select="@name" />
                                </xsl:element>
                            </li>
                        </xsl:for-each>
                        <xsl:for-each select="//method/error[@object=current()/@name]/..">
                            <li>
                                <xsl:element name="a">
                                    <xsl:attribute name="href">
                                        <xsl:value-of select="concat('#method', @name)" />
                                    </xsl:attribute>
                                    <xsl:value-of select="@name" />
                                </xsl:element>
                            </li>
                        </xsl:for-each>
                    </ul>
                </div>
                <xsl:element name="a">
                    <xsl:attribute name="href">
                        <xsl:text>#</xsl:text>
                        <xsl:value-of select="concat('json', @name)" />
                    </xsl:attribute>
                    <xsl:attribute name="data-rel">dialog</xsl:attribute>
                    <xsl:attribute name="data-transition">pop</xsl:attribute>
                    <xsl:attribute name="data-role">button</xsl:attribute>
                    <xsl:attribute name="data-theme">c</xsl:attribute>
                    <xsl:attribute name="data-icon">info</xsl:attribute>
                    <xsl:text>Example JSON</xsl:text>
                </xsl:element>
            </section>
            <xsl:call-template name="footer" />
        </xsl:element>

        <xsl:element name="div">
            <xsl:attribute name="data-role">page</xsl:attribute>
            <xsl:attribute name="data-theme">d</xsl:attribute>
            <xsl:attribute name="id">
                <xsl:value-of select="concat('json', @name)" />
            </xsl:attribute>
            <header data-role="header" data-position="fixed">
                <h1>
                    <xsl:value-of select="@name" />
                    <xsl:text> | JSON</xsl:text>
                </h1>
            </header>
            <section data-role="content" data-theme="b">
                <pre class="code">
                    <xsl:text>{
</xsl:text>
                    <xsl:for-each select="field">
                        <xsl:text>    "</xsl:text>
                        <xsl:value-of select="." />
                        <xsl:text>": "value",</xsl:text>
                        <xsl:text>
</xsl:text>
                    </xsl:for-each>
                    <xsl:text>}
</xsl:text>
                </pre>
            </section>
        </xsl:element>
    </xsl:template>

    
    <xsl:template match="method">
        <xsl:element name="article">
            <xsl:attribute name="data-role">page</xsl:attribute>
            <xsl:attribute name="data-theme">d</xsl:attribute>
            <xsl:attribute name="id">
                <xsl:value-of select="concat('method', @name)" />
            </xsl:attribute>
            <header data-role="header" data-position="fixed">
                <h1>
                    <xsl:value-of select="$title" />
                    <xsl:text> API | </xsl:text>
                    <xsl:value-of select="@name" />
                </h1>
                <xsl:call-template name="menu" />
            </header>
            <section data-role="content" data-theme="b">
                <div class="method">
                    <ul data-role="listview" data-inset="true">
                        <li data-role="list-divider" role="heading">
                            <xsl:text>Method: </xsl:text>
                            <xsl:value-of select="@name" />
                            <span class="http-method brackets">
                                <xsl:value-of select="@http" />
                            </span>
                        </li>
                        <xsl:apply-templates />
                    </ul>
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:value-of select="$apiUrl" />
                            <xsl:text>/console</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="rel">external</xsl:attribute>
                        <xsl:attribute name="data-role">button</xsl:attribute>
                        <xsl:attribute name="data-icon">info</xsl:attribute>
                        <xsl:attribute name="data-theme">c</xsl:attribute>
                        <xsl:text>Open Testconsole</xsl:text>
                    </xsl:element>
                </div>
            </section>
            <xsl:call-template name="footer" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>